package com.lagou.rpc.provider;

import com.lagou.rpc.provider.server.RpcServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ServerBootstrapApplication2 implements CommandLineRunner {


    @Autowired
    private RpcServer rpcServer;

    public static void main(String[] args) {
        SpringApplication.run(ServerBootstrapApplication2.class, args);
    }

    // 注意：springboot在启动后会遍历IOC容器中所有实现了CommandLineRunner接口的bean，并调用run方法，
    // 这里有两个启动类，并且@SpringBootApplication是一个包含了@Componenet的组合注解，任意启动一个，两个启动类的run方法都会被调用
    @Override
    public void run(String... args) throws Exception {
        System.out.println("8898 run");
        new Thread(new Runnable() {
            @Override
            public void run() {
                rpcServer.startServer("127.0.01", 8898);
            }
        }).start();
    }
}
